<extend name="common/base"/>

<block name="body">
<table class="table table-bordered" id="user_index" data-toggle="datagrid"

       data-options="{
                title: '用户余额变动日志',
                root: 'Rows',
                dataUrl: '{:url('getUserLists')}',
                rownumbers: true,
                pageSize: {$pageSize|default=50|intval},
                toolbarCustom: getSearchForm,
                rownumbersColWidth: 60,
                postData: getFormData,
                columns:[{
                        name: 'uid',
                        label: '用户号',
                        align: 'left',
                        width: '80'
                    },
                    {
                        label: '用户昵称',
                        name: 'nickname',
                        align: 'left',
                        width: '140'
                    },
                    {
                        label: '积分',
                        name: 'score',
                        width: 50,
                    },
                    {
                        label: '登录次数',
                        name: 'login',
                        align: 'right',
                        width: '60'
                    },
                    {
                        label: '最后登录时间',
                        name: 'last_login_time_text',
                        align: 'right',
                        width: '120',
                    },
                    {
                        label: '最后登录IP',
                        name: 'last_login_ip_text',
                        align: 'left',
                        width: '120',
                    },
                    {
                        label: '状态',
                        name: 'status_text',
                        align: 'left',
                        width: '80'
                    },
                    {
                        label: '操作',
                        name:'',
                        width: '80',
                        render: function(cell, row){
                            return getAction(cell, row);
                        }
                    }]
       }"
       >
</table>
</block>

<block name="script">
    <script type="text/javascript">
        function getAction(cell, row) {
        	html ='';
        	curl = '{:url("User/changeStatus")}';
        	curl += curl.indexOf('?')>=0?'&':'?';
        	if(row.status==1) {
        		html += '<a href="'+curl+'method=forbidUser&id='+row.uid+'" class="btn btn-warning" data-toggle="ajaxurl">禁用</a>';
        	} else {
                html += '<a href="'+curl+'method=resumeUser&id='+row.uid+'" class="btn btn-warning" data-toggle="ajaxurl">启用</a>';
        	}
            html += '<a href="'+curl+'method=deleteUser&id='+row.uid+'" class="btn btn-warning" data-toggle="ajaxurl">删除</a>';
            curl = '{:url("Auth/group")}';
            curl += curl.indexOf('?')>=0?'&':'?';
            html += '<a href="'+curl+'uid='+row.uid+'" class="btn btn-parimy" data-toggle="dialog">授权</a>';
        }

        function view(id, time){
            var url = '{:url("viewmoneylog")}';
            url += (url.indexOf('?') > 0 ? '&' : '?');
            window.location = url+'id='+id + '&time='+time;
        }
        function getSearchForm(){
            html = '<div class="input-group">';
            html += '<select id="type" class="form-control" style="width: 60px;"><option value="username">用户名</option><option value="uid" <if condition="$uid">selected=true</if>>用户号</option><option value="nickname">昵称</option></select>';
            html += '<input type="text" style="width: 100px;" size="10" class="form-control" name="keyword" value="<if condition="$uid">{$uid}</if>" id="keyword">';
            html += '<span class="input-group-addon">模糊搜索</span>';
            html += '<span class="input-group-addon rightborder"><input type="checkbox" name="like" value="1" id="like" data-toggle="icheck"></span>';
            html += '<span class="input-group-addon">起始日期</span>';
            html += '<input type="text" data-toggle="datepicker" style="width: 100px;" size="10" class="form-control" name="begindate" value="" id="begindate" max-date="enddate">';
            html += '<span class="input-group-addon">截止日期</span>';
            html += '<input type="text" data-toggle="datepicker" style="width: 100px;" size="10" class="form-control" name="enddate" value="" id="enddate" min-date="begindate">';
            html += '<span class="input-group-addon cursorpointer rightborder" onclick="return reSearch();"><i class="icon icon-search"></i> 查询</span>';
            html += '<span class="input-group-addon cursorpointer" onclick="return exports();"><i class="icon icon-signout"></i> 导出</span>';
            html += '</div>';
            return html;
        }
        function exports(){
            var dg = $('#user_index').data('zui.datagrid');
            dg.reload();
            dg.export('init');
        }
        function getFormData(){
            var keytype = $('#type').val();
            var keyword = $('#keyword').val();
            var like = $('#like').is(':checked');
            var data = {};
            if(like) {
                data['like'] = 1;
            }
            if(keyword) {
                data[keytype] = keyword;
            }
            var date = $('#begindate').val();
            if(date) {
                data['begindate'] = date;
            }
            var date = $('#enddate').val();
            if(date) {
                data['enddate'] = date;
            }
            return data;
        }
        function reSearch(){
            var oo = $('#user_index').data('zui.datagrid');
            oo.reload();
        }
    </script>
</block>
